﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace LeMigue.TeamPortal.Base.Mvc
{
    public class CheckTeam : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Type ReturnType = filterContext.Controller.GetType().GetMethods().Single(a => a.Name.ToLower() == filterContext.ActionDescriptor.ActionName.ToLower()).ReturnType;

            if(((TeamPortalController)filterContext.Controller).Team == null){
                if (ReturnType == typeof(ActionResult))
                {
                    filterContext.Result = new RedirectResult("~/Home");
                }
                else if (ReturnType == typeof(PartialViewResult))
                {
                
                }
                return;
            }
        }
    }
}
